#include "drogon/drogon.h"
#include "JobManager.h"
#include "yaml-cpp/yaml.h"
#include "WeatherTimer2.h"
#include "WeatherTimer3.h"
//
//template <typename T>
//T getYaml(YAML::Node node,std::vector<String> pathVec) {
//
//	std::vector<YAML::Node> nodePath;
//	nodePath.push_back(node);
//
//	for (auto i = 0;i< pathVec.size();i++)
//	{
//		String name = pathVec[i];
//		YAML::Node node1 = nodePath.back()[name];
//		if (!node1.IsDefined()) {
//			String msg = "yaml bad path [";
//			for (auto j=0;j!=i;j++)
//			{
//				msg += pathVec[j] + ":";
//			}
//			msg += name + "]";
//			throw YAML::Exception(node1.Mark(), msg.c_str());
//		}
//		nodePath.push_back(node1);
//	}
//
//	return nodePath.back().as<T>();
//}

void JobManager::start()
{
	String yamlFileName = Singleton(Environment).getAppPath() + "ZJ.yaml";
	try {
		YAML::Node node = YAML::LoadFile(yamlFileName);
		String cachePath = getYaml<String>(node, {"hxgis", "ZheJiang9", "CachePath"});
		String dataPath1 = getYaml<String>(node, {"hxgis", "ZheJiang9", "DataPath1"});
		String dataPath2 = getYaml<String>(node, {"hxgis", "ZheJiang9", "DataPath2"});
		String dataPath3 = getYaml<String>(node, {"hxgis", "ZheJiang9", "DataPath3"});
		int timeout = getYaml<int>(node, { "hxgis", "ZheJiang9", "Timeout" });
		int duration = getYaml<int>(node, { "hxgis", "ZheJiang9", "Duration" });
		//weatherTimer1 = std::make_unique<WeatherTimer1>();
		//weatherTimer1->start();
	}
	catch (const YAML::Exception& e) {
		LOG_ERROR << e.msg << "\n";
	}

	try {
		YAML::Node node = YAML::LoadFile(yamlFileName);
		String cachePath = getYaml<String>(node, { "hxgis", "ZheJiang11", "CachePath" });
		String dataPath1 = getYaml<String>(node, { "hxgis", "ZheJiang11", "DataPath1" });
		String dataPath2 = getYaml<String>(node, { "hxgis", "ZheJiang11", "DataPath2" });
		String dataPath3 = getYaml<String>(node, { "hxgis", "ZheJiang11", "DataPath3" });
		int expiredTime = getYaml<int>(node, { "hxgis", "ZheJiang11", "ExpiredTime" });
		int duration = getYaml<int>(node, { "hxgis", "ZheJiang11", "Duration" });
		String histVec = getYaml<String>(node, { "hxgis", "ZheJiang11", "Hist" });
		weatherTimer2 = std::make_unique<WeatherTimer2>();
		weatherTimer2->setDataPath1(dataPath1);
		weatherTimer2->setDataPath2(dataPath2);
		weatherTimer2->setDataPath3(dataPath3);
		weatherTimer2->setCachePath(cachePath);
		weatherTimer2->setHistVec(StringUtil::split(histVec,","));
		weatherTimer2->setCacheExpiredTime(expiredTime);
		//weatherTimer2->start(duration);
	}
	catch (const YAML::Exception& e) {
		LOG_ERROR << e.msg << "\n";
	}

	//weatherTimer3 = std::make_unique<WeatherTimer3>();
	//weatherTimer3->setDataPath1("E:\\volume");
	//weatherTimer3->setCachePath("E:\\test");
	//weatherTimer3->setDuration(10);
	//weatherTimer3->start();

}
